<template>
  <view class="film-trailer-popup" @click.prevent.stop="() => {}">
    <zm-popup :show.sync="visible" :overlay-style="overlayStyle" mode="center" width="100vw" background="transparent" @open="isShow = true" @close="onClose" @closed="isShow = false">
      <video v-if="isShow" id="video" class="video" :src="src"></video>
    </zm-popup>
  </view>
</template>

<script>
import hook from "@/mixins/hook"
import weixin from "@/mixins/weixin"
import { mitt } from "@/utils/mitt"
export default {
  name: "film-trailer-popup",
  mixins: [hook, weixin],
  data() {
    return {
      src: "",
      isShow: false,
      visible: false
    }
  },
  computed: {
    overlayStyle() {
      const style = {}
      style.background = "rgba(0,0,0,1)"
      return style
    }
  },
  mounted() {
    this.init()
  },
  destroyed() {
    mitt.off(`${this.useCurrentRoute()}-showFilmTrailer`)
  },
  methods: {
    async init() {
      await this.$nextTick()
      this.videoContext = uni.createVideoContext("video")
      mitt.on(`${this.useCurrentRoute()}-showFilmTrailer`, (src) => {
        if (src) {
          this.src = src
          this.open()
        }
      })
    },
    open() {
      this.visible = true
    },
    close() {
      this.visible = false
    },
    onClose() {
      // #ifdef APP-PLUS
      this.isShow = false
      // #endif
      this.videoContext?.pause()
      this.videoContext?.stop()
    }
  }
}
</script>

<style lang="scss" scoped>
.film-trailer-popup {
  z-index: 1100;
  .video {
    width: 100%;
  }
}
</style>
